<!--
 * @Descripttion: 
 * @version: 
 * @Author: Connor
 * @Date: 2021-03-02 09:03:50
 * @LastEditors: Connor
 * @LastEditTime: 2021-04-19 11:35:52
-->
<template>
  <div>
 <!-- <pre v-html="data"></pre> -->
    <div  class="minheight">
      <el-form :model="pickUpForm" ref="pickUpForm" :rules="rules" size="mini" >
            <el-form-item label="关联订单号" label-width="200px" prop="waybillNo">
              <el-input size="large" v-model="pickUpForm.waybillNo" type="textarea" rows="6" style="width: 400px;" ></el-input>
            </el-form-item>
            <div >
              <el-button size="mini" @click="dialogFormVisible = false">取 消</el-button>
              <el-button size="mini" type="primary" @click="saveWaybillNo()">保 存</el-button>
            </div>
      </el-form> 
    </div>
    
  </div>
</template>
<script>
import { closeDialog } from "@/utils";
import {ajax} from "@/store/yg/common/utils";
import LoginVue from '../../../../yg/auth/Login.vue';
export default {
 props: ["field","data"],
     data() {
      return {
        pickUpForm: {
          id:"",
          waybillNo:"",
          waybillNos:[],
        },
        pickSource:[],
        serviceSource:[],
        driverId:"",
        rules:{
           waybillNo: [
            { required: true, message: '请填写运单号', trigger: 'blur' }
          ],
        }
      };
     },
     mounted() {
      this.driversWaybillNo();
    }, 
    
    methods:
      {
        driversWaybillNo() {
          //console.log("this.$store.state.edit.row",this.$store.state.edit.row);
          this.pickUpForm.id = this.$store.state.edit.row["id"];
          const waybills =  this.$store.state.edit.row["waybills"];
          let waybillNo = "";
          if(waybills) {
            waybills.forEach(element => {
                 waybillNo += "\n"+element.waybillNo;
            });
          }
          this.pickUpForm.waybillNo = waybillNo.substring(1,waybillNo.length);
        },
        saveWaybillNo(){//修改运单号
          if(this._validateForm()) {
              this.pickUpForm.waybillNos = this.pickUpForm.waybillNo.split("\n");
              //console.log("this.pickUpForm",this.pickUpForm);
              ajax("updateWaybillNo", this.pickUpForm).then( res => {
                 // console.log(res);
                if (res.code != 200) {
                    this.$message.error('保存失败');
                  } else {
                    this.$message.success('保存成功');
                    this.closeDriverDrawer();
                    location.reload();
                  }
              },
              error => {
                console.log(error);
              }
            );
          }
        },
        closeDriverDrawer() {
          closeDialog();
          this.pickUpForm={
            id:"",
            waybillNo:"",
          },
          this.$refs['pickUpForm'].resetFields();
        },
        _validateForm() {
          let flag = true;
          this.$refs['pickUpForm'].validateField(['waybillNo'],(valid) => {
              if (valid !== '') {
                flag = false;
              }
          });
          return flag;
        },
      }
}
</script>
<style scoped>

</style>

<style lang="scss">
.row-item {
  color: #3f4652;
  line-height: 28px;
  margin-bottom: 14px;
}

  .maxheight {
    display: none;
  }

  
</style>
